/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package academia.gui;

import academia.gui.cadastro.CadastroInstrutor;
import academia.negocio.CriarTreino;
import academia.negocio.FichaTreino;
import academia.persistencia.DBAcademia;
import academia.persistencia.IDregistro;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Enéias
 */
public class TelaCriarTreino extends javax.swing.JFrame {
    Connection conn=null;
    ResultSet rs =null;
    PreparedStatement ps=null;
    /**
     * Creates new form TelaCriarTreino
     */
    public TelaCriarTreino() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        ficha = new javax.swing.JTextArea();
        btnCriar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        ficha.setColumns(20);
        ficha.setRows(5);
        jScrollPane1.setViewportView(ficha);

        btnCriar.setText("Criar");
        btnCriar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCriarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(51, 51, 51)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(110, 110, 110)
                        .addComponent(btnCriar)))
                .addContainerGap(64, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnCriar)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCriarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCriarActionPerformed
       conn=DBAcademia.ConnectDB();
       try{
                                String sql="INSERT INTO Treino(IDaluno,IDinstrutor,Ficha) VALUES(?,?,?)";
                                ps=conn.prepareStatement(sql);
                                ps.setInt(1,IDregistro.getId2());
                                ps.setInt(2,IDregistro.getId1());
                                ps.setString(3,ficha.getText());
                                
                                ps.execute();
                                JOptionPane.showMessageDialog(null,"Treino Criado Com Sucesso.");
                                new TelaInstrutor().setVisible(true);
                                this.dispose();
                            }catch(SQLException a){
                                JOptionPane.showMessageDialog(null,a);
                            }
          finally{
                 try {
                      rs.close();
                      ps.close();
                      } catch (SQLException ex) {
                            Logger.getLogger(CadastroInstrutor.class.getName()).log(Level.SEVERE, null, ex);
                      }
                 }
       
    }//GEN-LAST:event_btnCriarActionPerformed

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCriar;
    private javax.swing.JTextArea ficha;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
